package com.cheung.leetcode.greedy;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.greedy
 * @Author :  cheungming
 * @CreateTime : 2024-06-09 08:32:38
 * @Description : 找零
 * @Version : 1.0
 */
public class Code860Test {

    public boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;

        for (int bill : bills) {
            if (bill == 5) {
                five++;
            } else if (bill == 10) {
                if (five == 0) {
                    return false;
                }
                five--;
                ten++;
            } else if (bill == 20) {
                if (ten > 0 && five > 0) {
                    ten--;
                    five--;
                } else if (five >= 3) {
                    five -= 3;
                } else {
                    return false;
                }
            }
        }
        return true;
    }

    @Test
    public void test1() {
        int[] bills = {5, 5, 5, 10, 20};
        assert lemonadeChange(bills);
    }

    @Test
    public void test2() {
        int[] bills = {5, 5, 10, 10, 20};
        assert !lemonadeChange(bills);
    }
}
